<!DOCTYPE>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>字典编辑</title>
    <link rel="stylesheet" href="../static/lib/layui/css/layui.css"  media="all">
    <link rel="stylesheet" type="text/css" href="../static/plugin/layer/skin/layer.css">
    <style type="text/css">
        .layui-form{margin:0 20px;}
        .x-red{color:red;}
        .layui-form-item{line-height: 38px;}
    </style>
</head>
<body>
<div id="createApp">
    <div >
        <fieldset class="layui-elem-field layui-field-title" >
            <legend>字典</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" action="">
            <input type="hidden" name="id" v-model="parameter.id"   autocomplete="off" class="layui-input">
            <div class="layui-form-item">
                <label class="layui-form-label">字典名称 </label>
                <div class="layui-input-inline" >
                    <input type="text" name="name"  v-model="parameter.name" placeholder="请输入字典名称" autocomplete="off" class="layui-input" @blur="verify(parameter.name)">
                </div>
                <span class="x-red">*必填</span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">字典编号 </label>
                <div class="layui-input-inline" >
                    <input type="text" name="code"  v-model="parameter.code" placeholder="请输入字典编号" autocomplete="off" class="layui-input" @blur="verifyNum(parameter.code)">
                </div>
                <span class="x-red">*必填</span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">字典类型</label>
                <div class="layui-input-inline">
                    <input type="text" name="type" v-model="parameter.type" lay-verify="required" placeholder="请输入字典类型" autocomplete="off" class="layui-input" @blur="verify(parameter.type)">
                </div>
                <span class="x-red">*必填</span>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">字典描述</label>
                <div class="layui-input-inline">
                    <input type="text" name="description" v-model="parameter.description" lay-verify="required" placeholder="请输入字典描述" autocomplete="off" class="layui-input" @blur="verify(parameter.description)">
                </div>
                <span class="x-red">*必填</span>
            </div>

        </form>
        <div class="layui-form-item">
            <label class="layui-form-label"></label><button class="layui-btn" lay-submit="" lay-filter="demo2" @click="sub">提交</button>
        </div>
    </div>
</div>
<script src="../static/lib/jquery.min.js"></script>
<script src="../static/lib/layui/layui.js" charset="utf-8"></script>
<script src="../static/lib/vue.min.js"></script>
<script src="../static/lib/x-layui.js"></script>
<script type="text/javascript">
    var myid="${dictionaries.id}"
    if(myid==""){
        var kid=""
        //alert("1213")
    }else {
        kid="$!{dictionaries.id}"
       // alert(kid)
    }
    var VM = new Vue({
        el:"#createApp",
        data:{
            parameter:{
                name:'$!{dictionaries.name}',
                type:'$!{dictionaries.type}',
                code:'$!{dictionaries.code}',
                createTime:'$!{dictionaries.createTime}',
                updateTime:'$!{dictionaries.updateTime}',
                description:'$!{dictionaries.description}',
                id:kid
            }
        },
        methods:{
            verify:function (item) {
                if(item == ""){
                    layer.msg("必填项不能为空！", {icon: 1});
                    return false;
                }
            },
            verifyNum:function (item) {
                var _this = this;
                if(item == ""){
                    layer.msg("必填项不能为空！", {icon: 1});
                    return false;
                }else if(isNaN(item)){
                    layer.msg("字典编号必须为数字！", {icon: 1});
                    _this.parameter.code = "";
                    return false;
                }
            },
            sub:function () {
                var _this = this;
                if(this.parameter.name == "" ){
                    layer.msg("请输入字典名称！", {icon: 1});
                    return false;
                }else if(this.parameter.code == ""){
                    layer.msg("请输入字典编号！", {icon: 1});
                    return false;
                }
                else if(this.parameter.type == ""){
                    layer.msg("请输入字典类型！", {icon: 1});
                    return false;
                }
                else if(this.parameter.description == ""){
                    layer.msg("请输入字典描述！", {icon: 1});
                    return false;
                }
                $.ajax({
                    type: "post",
                    url: "../dictionaries/saveOrUpdate.do",
                    data: _this.parameter,
                    dataType: "json",
                    success: function(data){
                        //alert("sdsd")
                        //关闭窗口
                      var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                       parent.layer.close(index);
                       parent.window.location.reload();
                        window.location.href = "javascript:location.replace(location.href)";
                    }
                });
            }
        }
    });//vue 实例结束
    layui.use(['layer',"form",'laydate'], function(){
        var layer = layui.layer;
    });
</script>
</body>
</html>